package com.itheima.mm.wx.service.impl;

import com.itheima.mm.exception.BaseException;
import com.itheima.mm.pojo.WxMember;
import com.itheima.mm.wx.mapper.WxMemberMapper;
import com.itheima.mm.wx.service.WxMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @Description WxMemberServiceImpl
 * @Author kangwei
 * @Date 2024-06-28
 */
@Service
public class WxMemberServiceImpl implements WxMemberService {

    @Autowired
    private WxMemberMapper wxMemberMapper;

    /**
     * 加入用户的id(openid),封装为实体后调用mapper
     * @param
     */
    @Override
    public void updateCityCourse(Map updateData) {
        Integer result = wxMemberMapper.updateCityAndCourse(updateData);
        if (result == 0){
            throw new BaseException("更新数据失败");
        }
    }

    /**
     * 根据openId查询用户
     * @param openId
     * @return
     */
    @Override
    public WxMember findByOpenId(String openId) {
        WxMember wxMember = wxMemberMapper.findByOpenId(openId);

        return wxMember;
    }

    /**
     * 添加会员
     * @param wxMember
     */
    @Override
    public void add(WxMember wxMember) {
        Integer result = wxMemberMapper.addMember(wxMember);
        if (result == 0){
            throw new BaseException("添加会员失败");
        }

    }


}
